/**
 * Created by hda on 2017/6/1.
 */
define(['jquery', 'vue', 'ks-city'], function ($, Vue, ksCity) {
    var model = {};

    model.init = function (m) {
        console.log(ksCity);

        var vue = new Vue({
            el: '#el-location',
            data: {
                title: '选择省份',
                menu: '',
                step: 0,
                list_province: ksCity,
                list_city: {},
                list_district: {},
                selected_province: '',
                selected_city: '',
                selected_district: '',
            },
            methods: {
                goback: function () {
                    history.back();
                },
                gostep: function (step) {
                    if (step == 1) {
                        this.step = 0;
                        this.menu = '';
                        this.title = '选择省份';
                        $("#location_city").removeClass('ks-fade-r').hide();
                        $("#location_province").addClass('ks-fade-r').show();
                    }
                    if (step == 2) {
                        this.step = 1;
                        this.title = '选择城市';
                        this.menu = '返回省份';
                        $("#location_district").removeClass('ks-fade-r').hide();
                        $("#location_city").addClass('ks-fade-r').show();
                    }
                },
                bindProvince: function () {

                },
                bindCity: function () {

                },
                bindDistrict: function () {

                },
                chooseProvince: function (index, text) {
                    this.title = '选择城市';
                    this.menu = '返回省份';
                    this.step = 1;
                    this.list_city = this.list_province[index].children;
                    this.selected_province = text;
                    $("#location_province").hide();
                    $("#location_city").addClass('ks-fade-r').show();
                },
                chooseCity: function (index, text) {
                    this.title = '选择区域';
                    this.menu = '返回城市';
                    this.list_district = this.list_city[index].children;
                    this.selected_city = text;
                    this.step = 2;
                    $("#location_city").hide();
                    $("#location_district").addClass('ks-fade-r').show();
                },
                chooseDistrict: function (text) {
                    var location = this.selected_province + ' ' + this.selected_city + ' ' + text;
                    $("#edit_province").val(this.selected_province);
                    $("#edit_city").val(this.selected_city);
                    $("#edit_district").val(text);
                    $("#edit_location").html(location).removeClass('color-gray');

                    history.back();
                    // $("#ks-addressSelect-cache").remove();
                    // location.href='#addressSelect';
                    // $(this).parents('.ks-spa').remove();
                }
            },
            mounted: function () {
                this.bindProvince();
            }
        })


    }

    return model
})